<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>微信菜单</h2>
        <ol class="breadcrumb">
            <li>
                <a href="#">首页</a>
            </li>
            <li>
                <a href="#{:U('WeixinMenu/')}">微信菜单</a>
            </li>
            <li class="active">
                <strong>{$isEdit?'修改':'添加'}微信菜单</strong>
            </li>
        </ol>
    </div>
</div>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <div>
                        <button class="btn btn-link" type="button" onclick="history.back()">
                            <span class="fa fa-angle-left"></span>
                            返回
                        </button>
                    </div>
                    <form method="post" class="form-horizontal" id="form1">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">菜单名称</label>
                            <div class="col-sm-10">
                                <input value="{$m.title}" name="title" type="text" required class="form-control">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">父菜单</label>
                            <div class="col-sm-10">
                                {:W('Parts/combotree',['emptyValue'=>0,'emptyText'=>'(顶级菜单)','name'=>'parent_id','model'=>'weixin_menu','value'=>$m.parent_id])}
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">动作类型(type)</label>
                            <div class="col-sm-10">
                                {:W('parts/op',['name'=>'type','required'=>false,'key'=>'mat','value'=>$m.type,'htmlAttr'=>['id'=>'type']])}
                            </div>
                        </div>
                        <div id="key_area" style="display: none">
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">键值(key)</label>
                                <div class="col-sm-10">
                                    <input value="{$m.key}" name="key" type="text" required class="form-control">
                                </div>
                            </div>
                        </div>
                        <div id="media_id_area" style="display: none">
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">素材ID(media_id)</label>
                                <div class="col-sm-10">
                                    <input value="{$m.media_id}" name="media_id" type="text" required
                                           class="form-control">
                                </div>
                            </div>
                        </div>
                        <div id="url_area" style="display: none">
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">链接地址</label>
                                <div class="col-sm-10">
                                    <input value="{$m.url}" name="url" type="text" required class="form-control">
                                </div>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">排序号</label>
                            <div class="col-sm-10">
                                <input value="{$m.sort?:0}" name="sort" type="number" required class="form-control">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">是否有效</label>
                            <div class="col-sm-10">
                                {:W('parts/op',['name'=>'is_valid','key'=>'yn','value'=>$m.is_valid?:1])}
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">是否认证菜单</label>
                            <div class="col-sm-10">
                                {:W('parts/op',['name'=>'is_auth','key'=>'yn','value'=>$m.is_auth?:0])}
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button data-style="expand-left" class="btn btn-primary ladda-button" type="button"
                                        data-op="submit">确 定
                                </button>
                            </div>
                        </div>
                        <div>
                            <button class="btn btn-link" data-op="back" type="button">
                                <span class="fa fa-angle-left"></span>
                                返回
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    (function () {
        var fields = ['url_area', 'link_area', 'media_id_area','key_area'];

        function showInput(field) {
            for (var i = 0, len = fields.length; i < len; i++) {
                $('#' + fields[i]).hide();
            }
            if(field){
                $('#' + field+'_area').show();
            }
        }

        YForm.create('#form1', "{:U('saveModel')}", '{$m.id}');
        $('#type').change(function () {
            var v = $(this).val();
            switch (v) {
                case 'view':
                    showInput('url');
                    break;
                case 'click':
                    showInput('key');
                    break;
                case 'media_id':
                case 'view_limited':
                    showInput('media_id');
                    break;
                default:
                    showInput();
            }
        }).trigger('change');
    })();

</script>